var dateObj = require("../../date/date.js");
Page({
  data: {
    weatherInfo: '',
  },
  onLoad: function(options) {
    this.setData({
      livelist: dateObj.livelist
    })
    this.getUserLocation();
  },
  getUserLocation: function() {
    var that = this;
    wx.getLocation({
      type: 'wgs84',
      success: function(res) {
        let latitude = res.latitude
        let longitude = res.longitude
        wx.showLoading({
          title: '加载中',
        })
        wx.request({
          url: 'https://api.jisuapi.com/weather/query',
          data: {
            appkey: '5c3edc0aec17afaf', 
            location: latitude + "," + longitude
          },
          header: {
            'content-type': 'application/json'
          },
          success: function(res) {
            console.log(res.data.result)
            if (!res.data.result) {
              console.log('获取天气接口失败')
              return
            }
            if (res.statusCode === 200 && res.data.status == 0) {
              var result = res.data.result;
              that.setData({
                weatherInfo: result
              });
              wx.setStorageSync("weatherInfo", result);
            }
            wx.hideLoading()
          }
        })
      }
    })
  }
})